/******************************************************************************
* Copyright (C) 2021, BBI Technology Co.,Ltd All rights reserved.
*
* Author: Embedded software group
*
* file： bsp_lpm.c 
*
*
*Note：此文件位于bsp层，本文件提供低功耗的处理API接口
 ******************************************************************************/

#include "bsp_lpm.h"

// 此接口函数谨慎修改
void BSP_LowpowerMode_BeforeEnter_todo(void)
{
    ///< 打开GPIO外设时钟门控
    Sysctrl_SetPeripheralGate(SysctrlPeripheralGpio, TRUE);
    
    //swd as gpio
    //Sysctrl_SetFunc(SysctrlSWDUseIOEn, TRUE);

	///< 配置为数字端口
    M0P_GPIO->PAADS &= 0x0000;
    M0P_GPIO->PBADS &= 0x0000;
    M0P_GPIO->PCADS &= 0x0000;
    M0P_GPIO->PDADS &= 0x0000;

    ///< 配置为端口输出(无上下拉)
    M0P_GPIO->PADIR &= 0x0000;
    M0P_GPIO->PBDIR &= 0x0801;   /*Lpuart_rx(pb11)除外(测试收发正常)*/
    M0P_GPIO->PCDIR &= 0x0000;
    M0P_GPIO->PDDIR &= 0x0000;
	
	M0P_GPIO->PAPD &= 0x0000; /*1: 使能下拉  0: 禁止下拉*/
	M0P_GPIO->PBPD &= 0x0801;  
	M0P_GPIO->PCPD &= 0x0000;
	M0P_GPIO->PDPD &= 0x0000;
	
//	M0P_GPIO->PAPU &= 0x0000; /*1: 使能上拉  0: 禁止上拉*/
//	M0P_GPIO->PBPU &= 0x0801;  
//	M0P_GPIO->PCPU &= 0x0000;
//	M0P_GPIO->PDPU &= 0x0000;
	
	///< 端口输出低电平
	/*实际测量,mbus的tx,rx在空闲状态都为高电平,所以此pb00 and pb11 输出高电平*/
	M0P_GPIO->PAOUT = 0x0000;
	M0P_GPIO->PBOUT = 0x0801;
	M0P_GPIO->PCOUT = 0x0000;
	M0P_GPIO->PDOUT = 0x0000;
}
	
void BSP_LowpowerMode_Wakeup_todo(void)
{

	

}


///* 低功耗唤醒后需要做的事情*/
//void LowpowerMode_wakeup_todo(void)
//{	
//	///< 打开GPIO外设时钟门控
//    Sysctrl_SetPeripheralGate(SysctrlPeripheralGpio, TRUE);
//	
//    //swd as gpio
//	//Sysctrl_SetFunc(SysctrlSWDUseIOEn, TRUE); /*防止程序被swd读出*/
//	
//	//BSP_Timer3_init(250);	
//	
//	PORT_init();
//	ADCX_init();	
//	BSP_Valve_Init();  /*阀控IO初始化之后,调试串口不可使用！*/	
//}

//	while(1)
//	{	
//		mbus_cmd_parse();	
//		mbus_ack_process();	
//		//LpUart0_SendString(Testbuff, sizeof(Testbuff));
//		if(mcu_mode == Normal)
//		{
//			LowpowerMode_BeforeEnter_todo(); //功耗调试测试可以在这里进行	
//			Lpm_GotoDeepSleep(FALSE); /*demo board, test 0.3uA */
//			LowpowerMode_wakeup_todo();		
//		}			
//	}
//}
